<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>队伍审核</title>

<script type="text/javascript">
	$(function() {
		query();
	});

	
	//查询报名队伍信息
	function query() {
		$("#table").datagrid({
			title:"队伍信息",
			url : "<%=basePath%>dance/getActivityApply",
			 // pagination:true,//分页控件  
			queryParams : {
				teamCode : $.trim($('#code_s').val()),
				teamName : $.trim($('#name_s').val()),
				status : $.trim($('#status_s').val()),
			}

		});
	}

	//清空查询条件
	function reset() {
		$("input").val("");
		$("#status_s option:first").prop("selected", 'selected');
	}
	//新增活动报名
	function addAcApply() {
		
		//设置地址
		url = "<%=basePath%>dance/addActivityApply";
		//打开对话框
		$('#dlg').dialog('open').dialog('setTitle', '新增活动报名');
		//清空
		$('#fm').form('clear');
	}

	
	//编辑活动报名
	function editAcApply() {
		//选中的行
		var row = $('#table').datagrid('getSelected');
		if (row) {
			//设置地址
			url = "<%=basePath%>dance/updateAcApply";
			$('#dlg').dialog('open').dialog('setTitle', '编辑活动报名');
			$('#fm').form('load', row); 
		}else{
			$.messager.alert({
				title : 'Failed!',
				msg : '请先选中一行!',
			});
		}
	}
	//保存活动报名
	function saveAcApply() {
		$.ajax({
			type:"POST",
			data:getParams(),
			//根据事先设置的地址决定调用哪个方法
			url : url,
			success : function(result) {
				if (result.success) {
					$.messager.alert({
						title : 'Success!',
						msg : '成功!',
					});

					$('#dlg').dialog('close');
					//重新加载表格
					reload();
				} else {
					$.messager.alert({
						title : 'Failed!',
						msg : '失败!',
					});
				}
			},
			error : function(result) {
				$.messager.alert({
					title : 'Failed!',
					msg : '保存失败!',
				});
			}
		});

	}
	//删除活动报名
	function removeAcApply() {
		//勾选中的行
		var rows = $("#table").datagrid("getChecked");
		var ids = new Array();
		for (var i = 0; i < rows.length; i++) {
			ids.push(rows[i].id);
		}
		//如果选中了
		if (rows.length>0) {
			$.messager.confirm('Confirm', '确定要删除活动报名?', function(r) {
				if (r) {
					$.ajax({
						type:"POST",
						//传数组时需要设置
						traditional:true,
						data:{
							"ids":ids
						},
						url : "<%=basePath%>dance/removeActivityApply",
						success:function(result) {
						if (result.success) {
							$.messager.alert({
								title : 'Success',
								msg : '删除成功!',
							});
							//重新加载表格
							reload();
						}
					}
					});
				}
			});
		}else{
			$.messager.alert({
				title : 'Failed!',
				msg : '请先勾选要删除的行!',
			});
		}
	}
	//审核活动报名
	function applyActivity() {
		//勾选中的行
		var rows = $("#table").datagrid("getChecked");
		var ids = new Array();
		for (var i = 0; i < rows.length; i++) {
			ids.push(rows[i].id);
		}
		if (rows.length>0) {
			$.messager.confirm('Confirm', '确定要审核活动报名?', function(r) {
				if (r) {
					$.ajax({
						type:"POST",
						traditional:true,
						data:{
							"ids":ids
						},
						url : "<%=basePath%>dance/applyActivity",
						success:function(result) {
						if (result.success) {
							$.messager.alert({
								title : 'Success',
								msg : '审核成功!',
							});
							//重新加载表格
							reload();
						}
					}
					});
				}
			});
		}else{
			$.messager.alert({
				title : 'Failed!',
				msg : '请先勾选要审核的行!',
			});
		}
	}
	//驳回活动报名
	function rejectActivity() {
		//勾选中的行
		var rows = $("#table").datagrid("getChecked");
		var ids = new Array();
		for (var i = 0; i < rows.length; i++) {
			ids.push(rows[i].id);
		}
		if (rows.length>0) {
			$.messager.confirm('Confirm', '确定要驳回活动报名?', function(r) {
				if (r) {
					$.ajax({
						type:"POST",
						traditional:true,
						data:{
							"ids":ids
						},
						url : "<%=basePath%>dance/rejectActivity",
						success:function(result) {
						if (result.success) {
							$.messager.alert({
								title : 'Success',
								msg : '驳回成功!',
							});
							//重新加载表格
							reload();
						}
					}
					});
				}
			});
		}else{
			$.messager.alert({
				title : 'Failed!',
				msg : '请先勾选要驳回的行!',
			});
		}
	}
	//获得页面数据传递json参数
	function getParams(){
		var id=$.trim($("#id").val());
		//操作人
		var operator;
		//队伍id
		var teamId=$.trim($("#teamId").val()); 
		//队伍编码
		var teamCode=$.trim($("#teamCode").val());
		//队伍名称
		var teamName=$.trim($("#teamName").val());
		//活动id
		var activityId=$.trim($("#activityId").val());
		//活动编码
		var activityCode=$.trim($("#activityCode").val());
		//活动名称
		var activityName=$.trim($("#activityName").val());
		//活动第几期主键
		var activityDetailId=$.trim($("#activityDetailId").val());
		//活动第几期编码
		var activityDetailCode=$.trim($("#activityDetailCode").val());
		//活动第几期名称
		var activityDetailName=$.trim($("#activityDetailName").val());
		//队伍作品主键
		var teamWorkId=$.trim($("#teamWorkId").val());
		//队伍作品名称
		var teamWorkName=$.trim($("#teamWorkName").val());
		//队伍作品地址
		var teamWorkLocation=$.trim($("#teamWorkLocation").val());
		//创建人
		var creator;
		//备注
		var remark=$.trim($("#remark").val());
		return{
			"id":id,"operator":operator,"teamId":teamId,"teamCode":teamCode,"teamName":teamName,"activityId":activityId,
			"activityCode":activityCode,"activityName":activityName,"activityDetailId":activityDetailId,
			"activityDetailCode":activityDetailCode,"activityDetailName":activityDetailName,"teamWorkId":teamWorkId,
			"teamWorkName":teamWorkName,"teamWorkLocation":teamWorkLocation,"creator":creator,"remark":remark
		}
	}	
	

	//重新加载表格
	function reload(){
		$('#table').datagrid('reload');
	}
	//转化审核状态
	function statusFormat(val,row){
		var status;
		if(row.status=="0")
			status="已通过";
		if(row.status=="1")
			status="未审核";
		if(row.status=="2")
			status="已驳回";
		return status;
	}
	
</script>
</head>
<body>
	<tr>
		<th>队伍编码</th>
		<td><input type="text" id="code_s" name="code_s" /></td>
		<th>队伍名称</th>
		<td><input type="text" id="name_s" name="name_s" /></td>
		<th>审核状态</th>
		<td>
			<select id="status_s" name="status_s" style="width:147px;height:23px">
				<option value ="0">已通过</option>
				<option value ="1">未审核</option>
				<option value ="2">已驳回</option>
			</select>
		</td>
	</tr>
	<a href="javascript:void(0);" class="easyui-linkbutton" iconCls='icon-search' onclick="query();">查询</a>
	<a href="javascript:void(0);" class="easyui-linkbutton" iconCls='icon-remove' onclick="reset();">重置</a>
	<table id="table" class="easyui-datagrid" fitColumns="true" toolbar="#toolbar" singleSelect="true" checkOnSelect="false" selectOnCheck="false" pagination="true">
		<thead>
			<tr>
				<th field="id" checkbox="true">ID</th>
				<th field="teamCode" width="80">队伍编码</th>
				<th field="teamName" width="80" >队伍名称</th>
				<th field="activityCode" width="80" >活动编码</th>
				<th field="activityName" width="80">活动名称</th>
				<th field="activityDetailCode" width="80">活动明细数编码</th>
				<th field="activityDetailName" width="80">活动明细名称</th>
				<th field="teamWorkName" width="80">队伍作品名称</th>
				<th field="teamWorkLocation" width="100" >队伍作品地址</th>
				<th field="status" width="80" formatter="statusFormat">状态</th>
				<th field="creator" width="80">创建人</th>
				<th field="createTime" width="100" formatter="dateFormat" >创建时间</th>
				<th field="modifier" width="80">修改人</th>
				<th field="updateTime" width="100" formatter="dateFormat" >修改时间</th>
				<th field="remark" width="80">备注</th>
			</tr>
		</thead>
	</table>
	<!-- 工具栏 -->
	<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addAcApply()">新增</a> 
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editAcApply()">编辑</a> 
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="applyActivity()">审核</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="rejectActivity()">驳回</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeAcApply()">删除</a>
	</div>
	<!-- 对话框 -->
	<div id="dlg" class="easyui-dialog" style="width: 480px, height:380px; padding: 10px 20px" closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post">
			<table>
				<div style="display:none">
					<label>ID</label>
					<input id="id" name="id" class="easyui-validatebox" required="true">
				</div>	
				<tr>
					<td><label>队伍ID</label></td>
					<td><input id="teamId" name="teamId" class="easyui-validatebox" required="true"></td>
				</tr>
				<tr>
					<td><label>队伍编码</label></td>
					<td><input id="teamCode" name="teamCode" class="easyui-validatebox" required="true"></td>
				</tr>
				
				<tr>
					<td><label>队伍名称</label></td>
					<td><input id="teamName" name="teamName" class="easyui-validatebox" required="true"></td>
				</tr>
				<tr>
					<td><label>活动ID</label></td>
					<td><input id="activityId" name="activityId" class="easyui-validatebox" required="true"></td>
				</tr>
				<tr>
					<td><label>活动编码</label></td>
					<td><input id="activityCode" name="activityCode" class="easyui-validatebox" required="true"></td>
				</tr>
				
				<tr>
					<td><label>活动名称</label></td>
					<td><input id="activityName" name="activityName" class="easyui-validatebox" required="true"></td>
				</tr>
				<tr>
					<td><label>活动明细ID</label></td>
					<td><input id="activityDetailId" name="activityDetailId" class="easyui-validatebox" class="easyui-validatebox" required="true"></td>
				</tr>
				<tr>
					<td><label>活动明细数编码</label></td>
					<td><input id="activityDetailCode" name="activityDetailCode" class="easyui-validatebox" class="easyui-validatebox" required="true"></td>
				</tr>

				<tr>
					<td><label>活动明细名称</label></td>
					<td><input id="activityDetailName" name="activityDetailName" class="easyui-validatebox" required="true"></td>
				</tr>
				<tr>
					<td><label>队伍作品ID</label></td>
					<td><input id="teamWorkId" name="teamWorkId"  class="easyui-validatebox" required="true" ></td>
				</tr>
				<tr>
					<td><label>队伍作品名称</label></td>
					<td><input id="teamWorkName" name="teamWorkName"  class="easyui-validatebox" required="true" ></td>
				</tr>
				<tr>
					<td><label>队伍作品地址</label></td>
					<td><input id="teamWorkLocation" name="teamWorkLocation"  class="easyui-validatebox" required="true"></td>
				</tr>
				<tr>
					<td style="vertical-align:top"><label>备注</label></td>
					<td><input id="remark" name="remark"  class="easyui-textbox" style="height:50px" multiline="true"></td>
				</tr>

			</table>
		</form>
	</div>


	<!-- 按钮 -->
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveAcApply();">保存</a> <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
	</div>
</body>
</html>